import axios from 'axios';
import { API_NEW_VERSION, ALL_SERVICE_API } from '../api';

var qs = require('qs');

export const searchUsers = params => {
  return axios.get(ALL_SERVICE_API + '/stm-users', {params: params});
};

export const searchMebPersons = params => {
  return axios.get(API_NEW_VERSION + '/meb_persons', {params: params});
};

// 新框架
export const searchMebPersonsNew = params => {
  return axios.get(ALL_SERVICE_API + '/meb-personals', {params: params});
};

export const searchMebPersonsForSendSms = params => {
  return axios.get(API_NEW_VERSION + '/meb_persons_for_sendsms', {params: params});
};

export const searchUsersNoPage = params => {
  return axios.get(API_NEW_VERSION + '/meb_persons_for_sendsms/no_page', {params: params});
};

export const resetPwd = id => {
  return axios.post(ALL_SERVICE_API + '/stm-users/rest_password', qs.stringify({id: id}));
};

export const searchAllUsers = params => {
  return axios.get(API_NEW_VERSION + 'stm_users_no_page', {params: params});
};

export const saveUser = params => {
  return axios.post(ALL_SERVICE_API + '/stm-users', params);
};

export const modifyUser = (params) => {
  return axios.post(ALL_SERVICE_API + '/stm-users', params);
};

export const setCurrentOrgid = (id, orgId) => {
  return axios.post(API_NEW_VERSION + 'stm_users/' + id + '/default_organization/' + orgId);
};

export const addRoles = (id, roleIds) => {
  return axios.post(API_NEW_VERSION + 'stm_users/' + id + '/roles', roleIds);
};

export const addDataPermissions = (id, dataPermissionIds) => {
  return axios.post(API_NEW_VERSION + 'stm_users/' + id + '/data_permissions', dataPermissionIds);
};

export const deleteUsers = ids => {
  return axios.delete(ALL_SERVICE_API + '/stm-users/' + ids);
};

export const refreshOrgid = (orgId) => {
  return axios.post(API_NEW_VERSION + 'stm_users/refresh/orgid', qs.stringify({organizationId: orgId}));
};
